1838A - Blackboard List - CodeForces Solution


math

Please click on ads to support us..

C++ Code:

// Problem: A. Blackboard List
// Contest: Codeforces - Codeforces Round 877 (Div. 2)
// URL: https://codeforces.com/contest/1838/problem/A
// Memory Limit: 256 MB
// Time Limit: 1000 ms
//
// Powered by CP Editor (https://cpeditor.org)

//  !! Har Har Mahadev !!
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// #define ordered_set tree<int, null_type, less<int>, rb_tree_tag,
// tree_order_statistics_node_update> order_of_key(k) , find_by_order(k)
#define setbits(x) __builtin_popcountll(x)
#define fill(a, b) memset(a, b, sizeof(a))
#define f(i, x) for (int i = 0; i < x; i++)
#define fn(i, x) for (int i = 0; i <= x; i++)
#define fab(i, a, b) for (int i = a; i <= b; i++)
#define fastio                      \
  ios_base::sync_with_stdio(false); \
  cin.tie(NULL);                    \
  cout.tie(NULL)
#define all(x) (x).begin(), (x).end()
#define inf 1e18
#define mod 1000000007
#define pi 3.14159265359
#define sqrt sqrtl
ll gcd(ll a, ll b) {
  if (b > a) {
    return gcd(b, a);
  }
  if (b == 0) {
    return a;
  }
  return gcd(b, a % b);
}

ll expo(ll a, ll b, ll m) {
  ll res = 1;
  while (b > 0) {
    if (b & 1) res = (res * a) % m;
    a = (a * a) % m;
    b = b >> 1;
  }
  return res % m;
}
int nCr(int n, int r) {
  if (n < r) return 0;
  if (r > n - r) r = n - r;
  ll ans = 1;
  ll i;
  for (i = 1; i <= r; i++) {
    ans = (ans * (n - r + i));
    ans /= i;
  }
  return ans;
}
void solve() {
  ll n;
  cin >> n;
  vector<ll> v(n);
  f(i, n) cin >> v[i];
  sort(all(v));
  if (v[0] < 0)
    cout << v[0] << endl;
  else
    cout << v[n - 1] << endl;
  return;
}
int main() {
  fastio;
  ll t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}


Comments

Submit
0 Comments
More Questions

144. Binary Tree Preorder Traversal
137. Single Number II
130. Surrounded Regions
129. Sum Root to Leaf Numbers
120. Triangle
102. Binary Tree Level Order Traversal
96. Unique Binary Search Trees
75. Sort Colors
74. Search a 2D Matrix
71. Simplify Path
62. Unique Paths
50. Pow(x, n)
43. Multiply Strings
34. Find First and Last Position of Element in Sorted Array
33. Search in Rotated Sorted Array
17. Letter Combinations of a Phone Number
5. Longest Palindromic Substring
3. Longest Substring Without Repeating Characters
1312. Minimum Insertion Steps to Make a String Palindrome
1092. Shortest Common Supersequence
1044. Longest Duplicate Substring
1032. Stream of Characters
987. Vertical Order Traversal of a Binary Tree
952. Largest Component Size by Common Factor
212. Word Search II
174. Dungeon Game
127. Word Ladder
123. Best Time to Buy and Sell Stock III
85. Maximal Rectangle
84. Largest Rectangle in Histogram